package com.datong.server.factory.simpleFactory;

import com.datong.server.factory.simpleFactory.calculate.OperationAdd;
import com.datong.server.factory.simpleFactory.calculate.OperationDiv;
import com.datong.server.factory.simpleFactory.calculate.OperationMul;
import com.datong.server.factory.simpleFactory.calculate.OperationSub;

//简单工厂模式：违背开闭原则（新增功能时不仅要加算法，还需更改工厂类）
public class FactoryOperation {
    public static Operation createOpterate(String operate){
        Operation operation = null;
        switch (operate){
            case "+":
                operation = new OperationAdd();
                break;
            case "-":
                operation = new OperationSub();
                break;
            case "*":
                operation = new OperationMul();
                break;
            case "/":
                operation = new OperationDiv();
                break;
            default:
                System.out.println("运算符不存在...");
        }
        return operation;
    }
}
